import request from '@/utils/request'

// 获取房间列表
export function getRoomList() {
  return request({
    url: '/rooms',
    method: 'GET'
  })
}

// 获取房间列表 (兼容旧版本)
export function getRooms() {
  return getRoomList()
}

// 创建房间
export function createRoom(data) {
  return request({
    url: '/rooms',
    method: 'POST',
    data
  })
}

// 加入房间
export function joinRoom(roomId) {
  return request({
    url: `/rooms/${roomId}/join`,
    method: 'POST'
  })
}

// 获取房间信息
export function getRoomInfo(roomId) {
  return request({
    url: `/rooms/${roomId}`,
    method: 'GET'
  })
}

// 获取房间用户列表
export function getRoomUsers(roomId) {
  return request({
    url: `/rooms/users?room_id=${roomId}`,
    method: 'GET'
  })
}

// 离开房间
export function leaveRoom(roomId, userId) {
  return request({
    url: `/rooms/${roomId}`,
    method: 'DELETE',
    headers: {
      'X-User-Id': userId
    }
  })
}

// 获取房间消息历史
export function getMessageHistory(roomId) {
  return request({
    url: `/rooms/${roomId}/messages`,
    method: 'GET'
  })
}

// 发送消息
export function sendMessage(data) {
  return request({
    url: '/rooms/messages',
    method: 'POST',
    data
  })
}

// 上报消息已读
export function markMessageAsRead(roomId, msgId) {
  return request({
    url: `/rooms/${roomId}/messages/${msgId}/read`,
    method: 'POST'
  })
}

// 设置房间为匹配中
export function setRoomMatching(roomId) {
  return request({
    url: `/rooms/${roomId}/matching`,
    method: 'POST'
  })
}

// 取消房间匹配
export function cancelRoomMatching(roomId) {
  return request({
    url: `/rooms/${roomId}/cancel-matching`,
    method: 'POST'
  })
}

// 获取房间用户准备状态
export function getRoomReadyStatus(roomId) {
  return request({
    url: `/rooms/ready-status?room_id=${roomId}`,
    method: 'GET'
  })
}

// 更新用户准备状态
export function updateUserReadyStatus(data) {
  return request({
    url: '/user/ready-status',
    method: 'POST',
    data
  })
}